package com.atguigu.blog.service.impl;

import com.atguigu.blog.dao.ArticleDao;
import com.atguigu.blog.pojo.Article;
import com.atguigu.blog.service.ArticleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 这里分页使用的是pagehelper
 */
@Service
@Transactional(readOnly = false)
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, Article> implements ArticleService {

    @Override
    public List<Article> findAll() {
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("article_status", "Y");
        queryWrapper.orderByDesc("create_date");
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public Article findById(String id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<Article> findByUsername(String username) {
        QueryWrapper<Article> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("article_status", "Y");
        queryWrapper.eq("username", username);
        queryWrapper.orderByDesc("create_date");
        return baseMapper.selectList(queryWrapper);
    }
}